<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>
<!--{hook user_create_start.htm}-->
<div class="row">
	<div class="col-lg-6 mx-auto">
		<div class="card">
			<div class="card-header">
				请绑定登录账号
			</div>
			<div class="card-body">
				<form action="<?php echo url('wx_initialize-update');?>" method="post" id="form">
					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon-user"></i></span>
						</div>
						<input type="text" class="form-control" placeholder="<?php echo lang('username');?>" name="username" id="username" value="<?php echo $info['username'];?>">
					</div>
					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon-envelope"></i></span>
						</div>
						<input type="email" class="form-control" placeholder="<?php echo lang('email');?>" name="email" id="email" required>
					</div>
					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon-lock"></i></span>
						</div>
						<input type="password" class="form-control" placeholder="登录密码" name="password" id="password" required>
					</div>
					
					<div class="form-group">
						<button type="submit" class="btn btn-primary btn-block" id="submit" ><?php echo lang('next_step');?></button>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<?php include _include(APP_PATH.'view/htm/footer.inc.htm');?>
<script src="<?php echo $conf['view_url'];?>js/md5.js"></script>
<script>
var jform = $('#form');
var jsubmit = $('#submit');
var jsendsubmit = $('#sendinitpw');
var referer = '<?php echo http_referer();?>';
jsendsubmit.on('click', function() {
	jform.reset();
	jsendsubmit.button('loading');
	var postdata = jform.serialize();
	$.xpost(jsendsubmit.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$('#password').focus();
			var t = 60; // 倒计时
			jsendsubmit.button('<?php echo lang('user_send_sucessfully');?> 60 ');
			jsubmit.button('reset');
			// 倒计时，重新发送
			var handler = setInterval(function() {
				jsendsubmit.button('<?php echo lang('user_send_sucessfully');?> '+(--t)+' ');
				if(t == 0) {
					clearInterval(handler);
					jsendsubmit.button('reset');
				}
			}, 1000);
		} else if(code < 0) {
			$.alert(message, -1);
			jsendsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsendsubmit.button('reset');
		}
	});
	return false;
});
jform.on('submit', function() {
	var postdata = jform.serializeObject();
	jsubmit.button('loading');
	postdata.password = $.md5(postdata.password);
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			
			// ----------> 弹出层预留
			if(typeof arg1 != 'undefined') {
				var jmodal = arg1;
			}
			if(typeof arg2 != 'undefined') {
				var callback = arg2;
				callback(message);
			}
			
			$.alert(message);
			jsubmit.button(message).delay(3000).location(referer);
		} else if(code < 0) {
			$.alert(message, -1);
			jsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsubmit.button('reset');
		}
	});
	return false;
});

</script>